package com.hw01.controller;

import java.time.LocalDate;
import java.util.List;

import com.hw01.vo.EmployeeWorkloadsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import com.hw01.common.Result;
import com.hw01.service.EmployeeWorkloadsService;
import com.hw01.vo.EmployeeWorkloadsSumVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.multipart.MultipartFile;

/**
 * 员工提交工作量管理
 */

@RestController
@Api("员工提交工作量管理")
@RequestMapping("/workloads")
public class EmployeeWorkloadsController {

    @Autowired
    private EmployeeWorkloadsService employeeWorkloadsService;

    @GetMapping("/list")
    @ApiOperation("员工提交工作量记录")
    @ResponseBody
    public Result<List<EmployeeWorkloadsVo>> getEmployeeWorkloadsList(@ApiParam(value = "员工id", required = true) Long userId,
                                                                      @ApiParam(value = "年份", required = true) String year, @ApiParam(value = "月份", required = true) String month) {
        return employeeWorkloadsService.getEmployeeWorkloadsList(userId, year, month);
    }

    @GetMapping("/get")
    @ApiOperation("员工查询工作量")
    @ResponseBody
    public Result<EmployeeWorkloadsSumVo> getEmployeeWorkloads(@ApiParam(value = "员工id", required = true) Long userId,
                                                               @ApiParam(value = "年份", required = true) String year, @ApiParam(value = "月份", required = true) String month) {
        return employeeWorkloadsService.getEmployeeWorkloads(userId, year, month);
    }

    @GetMapping("/committed")
    @ApiOperation("员工提交工作量")
    public Result<Boolean> committedWorkloads(@ApiParam(value = "员工id", required = true) Long userId,
        @ApiParam(value = "提交日期", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate submissionDate,
        @ApiParam(value = "提交工作量", required = true) Byte committedWorkloads) {
        return employeeWorkloadsService.committedWorkloads(userId, submissionDate, committedWorkloads);
    }

    @PostMapping("/leaderVerify")
    @ApiOperation("队长确认工作量")
    public Result<String> leaderVerify(
            @ApiParam(value = "主键id", required = true) @RequestParam("id") Long id,
            @ApiParam(value = "核实图片", required = true) @RequestParam("file") MultipartFile file) {
        return employeeWorkloadsService.leaderVerify(id, file);
    }


}
